<template>
	<view style="padding-bottom: 50rpx;">
		<view class="padding margin radius bg-white" style="">
			<view class="text-19">当前余额</view>
			<view class="flex justify-between margin-top">
				<view class="text-bold text-black">¥<text style="font-size: 34px;">{{inviterRecord}}</text></view>
				<view class="" style="position: relative;overflow: hidden;width: 90px;">
					<view style="position: absolute;bottom:0;">
						<!-- <view class="flex"> -->
						<button @tap="getOut" class="cu-btn round">立即提现</button>
						<!-- </view> -->
					</view>
				</view>
			</view>
		</view>
		<!-- 公告 -->
		<!-- v-if="TabCur == 0" -->
		<view class="gg flex align-center justify-center" v-if="noticeList.length>0" style="margin-bottom: 10px;">
			<view class="gg-box flex align-center justify-between">
				<image src="../../static/images/index/jingrong.png" mode=""></image>
				<swiper :autoplay="true" :vertical="true" :interval="4000" :circular="true" :indicator-dots="false"
					class="gg-box-swiper">
					<block v-for="(item, index) in noticeList">
						<swiper-item @tap='goMsg(item.url)'>
							<view class="gg-box-swiper-t">{{item.title}}</view>
						</swiper-item>
					</block>
				</swiper>
			</view>
		</view>
		<view class="margin padding bg-white radius">
			<view class="u-font-16 text-bold margin-bottom">邀请明细</view>
			<!-- <view class="flex justify-between" style="line-height: 30px;" v-for="(item,index) in userList" >
				<view class="flex" style="width: 300rpx;">
					<u-image :src="item.avatar" width="30px" mode="widthFix"></u-image>
					<view class="margin-left-sm userName_view">{{item.userName}}</view>
				</view>
				<view style="width: 120rpx;">邀请好友</view>
				<view style="width: 120rpx;">
					<text class="margin-left text-red">赚{{item.money}}</text>
				</view>
			</view> -->

			<view class="flex justify-between align-center" style="margin-bottom: 40rpx;"
				v-for="(item,index) in userList">
				<view class="flex align-center">
					<image :src="item.avatar?item.avatar:require('@/hl/logo/logo.png')"
						style="width: 80rpx;height:80rpx;border-radius: 50rpx;"></image>
					<view class="margin-left-sm">
						<view class="userName_view">{{item.userName}}</view>
						<view class="text-cut" style="font-size: 24rpx;" v-if="item.userType && item.userType == 2">二级好友
						</view>
						<view class="text-cut" style="font-size: 24rpx;" v-else>一级好友
						</view>
						<!-- <u-image :src="item.avatar" width="30px" mode="widthFix"></u-image> -->
					</view>
				</view>
				<view class="margin-left flex-sub text-right">
					<!-- <text class="margin-left text-red">赚{{item.money}}</text> -->
					<text class="margin-left text-red"></text>
				</view>
			</view>

			<empty v-if="userList.length == 0" />
		</view>
	</view>
</template>

<script>
	import empty from '../../components/empty.vue'
	export default {
		components: {
			empty
		},
		data() {
			return {
				page: 1,
				limit: 50,
				userList: [],
				inviterRecord: '',
				noticeList: []
			}
		},
		onLoad() {
			this.getData()
			this.getInviter()
		},
		onReachBottom: function() {
			this.page = this.page + 1;
			this.getInviter();
		},
		onPullDownRefresh: function() {
			this.page = 1;
			this.getData();
			this.getInviter();
		},
		onShow() {
			this.getMsg()
		},
		methods: {
			// 公告
			getMsg() {
				let data = {
					page: 1,
					limit: 100,
					state: 104
				}
				this.$u.api.msg(data).then(res => {
					if (res.code == 0) {
						this.notice = res.data.list
						res.data.list.forEach(res => {
							this.noticeList.push(res)
						})
					} else {
						uni.showToast({
							title: res.msg,
							duration: 1000,
							icon: 'none'
						});
					}
				})
			},
			getData() {
				let data = {
					page: this.page,
					limit: this.limit
				}
				this.$u.api.queryInviter(data).then(res => {
					if (res.code == 0) {
						this.inviterRecord = res.data.inviteMoney.money
					} else {
						uni.showToast({
							title: res.msg,
							duration: 1000,
							icon: 'none'
						});
					}
				})
			},
			getInviter() {
				let data = {
					page: this.page,
					limit: this.limit
				}
				this.$u.api.inviter(data).then(res => {
					if (res.code == 0) {
						if (this.page == 1) {
							this.userList = res.data.list
						} else {
							this.userList = [...this.userList, ...res.data.list]
						}
						uni.stopPullDownRefresh();
					} else {
						uni.showToast({
							title: res.msg,
							duration: 1000,
							icon: 'none'
						});
					}
				})
			},
			getOut() {
				uni.navigateTo({
					url: '/me/invite/cashDetail'
				});
			},
		}
	}
</script>

<style lang="scss" scoped>
	.gg {
		width: 100%;
		height: auto;
		margin-top: 20rpx;

		.gg-box {
			width: 686rpx;
			height: 62rpx;
			background-color: #FFF2F4;
			border-radius: 32rpx;
			padding: 0 30rpx;

			image {
				width: 36rpx;
				height: 36rpx;
			}
		}

		.gg-box-swiper {
			width: calc(100% - 56rpx);
			height: 100%;
		}

		.gg-box-swiper-t {
			width: 100%;
			height: 100%;
			color: #FD4F65;
			line-height: 62rpx;
			font-size: 26rpx;
			overflow: hidden;
			white-space: nowrap;
			text-overflow: ellipsis;
		}
	}

	.cu-btn {
		background: #ECEEFE;
		color: #8B8FF0;
		font-weight: bold;
		font-size: 14px;
	}

	.userName_view {
		width: 280rpx;
		text-overflow: ellipsis;
		overflow: hidden;
		white-space: nowrap;
		margin-bottom: 4rpx;
	}
</style>